package ar.Location.UI;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import ar.Location.Weather_2.ForecastDay;
import ar.Location.Weather_2.LocalWeatherProvider;
import ar.activity.R.id;

public class WeatherItemView extends LinearLayout {
	final char degree = (char) 0x00B0;
	
	public Context mContext = null;
	public TextView txtViewWeekday = null;
	public TextView txtViewWeather = null;
	public TextView txtViewLowTemp = null;
	public TextView txtViewHighTemp = null;
	
	public ImageView imgViewConditions = null;
	
	public WeatherItemView(Context context) {
		super(context);
		initContext(context);
		initView();
	}

	private void initContext(Context context) {
		// TODO Auto-generated method stub
		mContext = context;
	}
	
	private void initView() {
		// TODO Auto-generated method stub
		inflate(mContext, ar.activity.R.layout.weather_item, this);
		
		txtViewWeather = (TextView)findViewById(id.lwTxtViewWeather);
		txtViewWeekday = (TextView)findViewById(id.lwTxtViewWeekDay);
		txtViewHighTemp = (TextView)findViewById(id.lwTxtViewHighTemp);
		txtViewLowTemp = (TextView)findViewById(id.lwTxtViewLowTemp);
		
		imgViewConditions = (ImageView)findViewById(id.lwImgViewWeather);
	}

	public void bindData(ForecastDay forecastDay) {
		if(forecastDay != null) {
			String highTempString = forecastDay.highTempC + " " + degree + "C " + "(" + forecastDay.highTempF + " " + degree + "F" + ")";
			String lowTempString = forecastDay.lowTempC + " " + degree + "C " + "(" + forecastDay.lowTempF + " " + degree + "F" + ")";
			txtViewWeather.setText(forecastDay.conditions);
			txtViewWeekday.setText(forecastDay.dayOfWeek);
			txtViewLowTemp.setText(lowTempString);
			txtViewHighTemp.setText(highTempString);
			
			int resId = LocalWeatherProvider.getResId(forecastDay.conditions);
			if (resId == -1) {
				imgViewConditions.setImageBitmap(null);
				imgViewConditions.setVisibility(View.GONE);
			} else {
				imgViewConditions.setImageResource(resId);
			}
		}
 	}
}
